package com.glacier.invoke;

import com.glacier.utils.MethodHandlesUtils;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * date 2021-06-03 17:39
 *
 * @author glacier
 * @version 1.0
 */
public class MyInvocationHandler implements InvocationHandler {
	
	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		Object result = null;
		// 进行业务增强
		System.out.println("JDK动态代理对业务进行了增强处理");
		if (method.isDefault()) {
			System.out.println("调用接口默认方法");
			result = MethodHandlesUtils.findMethodHandle(method)
					.bindTo(proxy)
					.invokeWithArguments(args);
		} else {
			System.out.println("调用接口方法\t" + method.getName());
		}
		System.out.println("JDK动态代理对业务进行了增强处理结束");
		return result;
	}
}
